home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 April / macformat-049.iso / mac / Shareware Plus / Developers / dropg++ / usr / include / sys / wait.h < prev   
Encoding:
C/C++ Source or Header  |  1997-02-20  |  5.4 KB  |  157 lines  |  [TEXT/R*ch]

  1. /*
  2.  * Copyright (c) 1982, 1986, 1989, 1993
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)wait.h    8.1 (Berkeley) 6/2/93
  34.  */
  35.  
  36. /*
  37.  * This file holds definitions relevent to the wait4 system call
  38.  * and the alternate interfaces that use it (wait, wait3, waitpid).
  39.  */
  40.  
  41. /*
  42.  * Macros to test the exit status returned by wait
  43.  * and extract the relevant values.
  44.  */
  45. #ifdef _POSIX_SOURCE
  46. #define    _W_INT(i)    (i)
  47. #else
  48. #define    _W_INT(w)    (*(int *)&(w))    /* convert union wait to int */
  49. #define    WCOREFLAG    0200
  50. #endif
  51.  
  52. #define    _WSTATUS(x)    (_W_INT(x) & 0177)
  53. #define    _WSTOPPED    0177        /* _WSTATUS if process is stopped */
  54. #define WIFSTOPPED(x)    (_WSTATUS(x) == _WSTOPPED)
  55. #define WSTOPSIG(x)    (_W_INT(x) >> 8)
  56. #define WIFSIGNALED(x)    (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0)
  57. #define WTERMSIG(x)    (_WSTATUS(x))
  58. #define WIFEXITED(x)    (_WSTATUS(x) == 0)
  59. #define WEXITSTATUS(x)    (_W_INT(x) >> 8)
  60. #ifndef _POSIX_SOURCE
  61. #define WCOREDUMP(x)    (_W_INT(x) & WCOREFLAG)
  62.  
  63. #define    W_EXITCODE(ret, sig)    ((ret) << 8 | (sig))
  64. #define    W_STOPCODE(sig)        ((sig) << 8 | _WSTOPPED)
  65. #endif
  66.  
  67. /*
  68.  * Option bits for the third argument of wait4.  WNOHANG causes the
  69.  * wait to not hang if there are no stopped or terminated processes, rather
  70.  * returning an error indication in this case (pid==0).  WUNTRACED
  71.  * indicates that the caller should receive status about untraced children
  72.  * which stop due to signals.  If children are stopped and a wait without
  73.  * this option is done, it is as though they were still running... nothing
  74.  * about them is returned.
  75.  */
  76. #define WNOHANG        1    /* dont hang in wait */
  77. #define WUNTRACED    2    /* tell about stopped, untraced children */
  78.  
  79. #ifndef _POSIX_SOURCE
  80. /* POSIX extensions and 4.2/4.3 compatability: */
  81.  
  82. /*
  83.  * Tokens for special values of the "pid" parameter to wait4.
  84.  */
  85. #define    WAIT_ANY    (-1)    /* any process */
  86. #define    WAIT_MYPGRP    0    /* any process in my process group */
  87.  
  88. #include <machine/endian.h>
  89.  
  90. /*
  91.  * Deprecated:
  92.  * Structure of the information in the status word returned by wait4.
  93.  * If w_stopval==WSTOPPED, then the second structure describes
  94.  * the information returned, else the first.
  95.  */
  96. union wait {
  97.     int    w_status;        /* used in syscall */
  98.     /*
  99.      * Terminated process status.
  100.      */
  101.     struct {
  102. #if BYTE_ORDER == LITTLE_ENDIAN 
  103.         unsigned int    w_Termsig:7,    /* termination signal */
  104.                 w_Coredump:1,    /* core dump indicator */
  105.                 w_Retcode:8,    /* exit code if w_termsig==0 */
  106.                 w_Filler:16;    /* upper bits filler */
  107. #endif
  108. #if BYTE_ORDER == BIG_ENDIAN 
  109.         unsigned int    w_Filler:16,    /* upper bits filler */
  110.                 w_Retcode:8,    /* exit code if w_termsig==0 */
  111.                 w_Coredump:1,    /* core dump indicator */
  112.                 w_Termsig:7;    /* termination signal */
  113. #endif
  114.     } w_T;
  115.     /*
  116.      * Stopped process status.  Returned
  117.      * only for traced children unless requested
  118.      * with the WUNTRACED option bit.
  119.      */
  120.     struct {
  121. #if BYTE_ORDER == LITTLE_ENDIAN 
  122.         unsigned int    w_Stopval:8,    /* == W_STOPPED if stopped */
  123.                 w_Stopsig:8,    /* signal that stopped us */
  124.                 w_Filler:16;    /* upper bits filler */
  125. #endif
  126. #if BYTE_ORDER == BIG_ENDIAN 
  127.         unsigned int    w_Filler:16,    /* upper bits filler */
  128.                 w_Stopsig:8,    /* signal that stopped us */
  129.                 w_Stopval:8;    /* == W_STOPPED if stopped */
  130. #endif
  131.     } w_S;
  132. };
  133. #define    w_termsig    w_T.w_Termsig
  134. #define w_coredump    w_T.w_Coredump
  135. #define w_retcode    w_T.w_Retcode
  136. #define w_stopval    w_S.w_Stopval
  137. #define w_stopsig    w_S.w_Stopsig
  138.  
  139. #define    WSTOPPED    _WSTOPPED
  140. #endif /* _POSIX_SOURCE */
  141.  
  142. #ifndef KERNEL
  143. #include <sys/types.h>
  144. #include <sys/cdefs.h>
  145.  
  146. __BEGIN_DECLS
  147. struct rusage;    /* forward declaration */
  148.  
  149. pid_t    wait __P((int *));
  150. pid_t    waitpid __P((pid_t, int *, int));
  151. #ifndef _POSIX_SOURCE
  152. pid_t    wait3 __P((int *, int, struct rusage *));
  153. pid_t    wait4 __P((pid_t, int *, int, struct rusage *));
  154. #endif
  155. __END_DECLS
  156. #endif
  157.